import React from 'react';
import { FormPanel, type FormPanelObject, InputType } from 'lfun-bg-comp';
import { Modal, message } from 'antd';
import { GENDER } from '@/constant/basicOptions';
import utils from '@/utils';
import { StuNewStudentSrv } from '@/service/student/newStudent';

const Create: React.FC<{ show: boolean; onChange: Function; value: any }> = ({ show, onChange, value }) => {
  const list = [
    {
      title: '',
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      inputs: [
        {
          label: '姓名',
          name: 'student_name',
          key: 'student_name',
          disabled: () => true,
        },
        {
          label: '性别',
          name: 'student_gender',
          key: 'student_gender',
          inputType: InputType.select,
          renderOption: GENDER,
          disabled: () => true,
        },
        {
          label: '证件号码',
          name: 'id_number',
          key: 'id_number',
          disabled: () => true,
          textRange: [0, 30],
        },
        {
          label: '报名号',
          name: 'enrollment_number',
          key: 'enrollment_number',
          disabled: () => true,
        },
        {
          label: '届别',
          name: 'class',
          key: 'class',
          inputType: InputType.select,
          renderOption: [],
          disabled: () => true,
        },
        {
          label: '年级',
          name: 'grade',
          key: 'grade',
          inputType: InputType.select,
          renderOption: [],
          disabled: () => true,
        },
        {
          label: '班级',
          name: 'class',
          key: 'class',
          inputType: InputType.select,
          renderOption: [],
          disabled: () => true,
        },
        {
          label: '流出时间',
          name: 'departure_time',
          key: 'departure_time',
          required: true,
          inputType: InputType.date,
        },
        {
          label: '流出原因',
          name: 'departure_reason',
          key: 'departure_reason',
          required: false,
          inputType: InputType.textarea,
          span: 24,
          textRange: [0, 500],
          props: {
            labelCol: { span: 2 },
            wrapperCol: { span: 22 },
          },
        },
      ],
    },
  ];

  return (
    <>
      <Modal title="流出" width="60%" footer={[]} open={show} onCancel={() => onChange(false)}>
        <FormPanel
          btnsAlign="center"
          restBtnText="返回"
          submitBtnText="确定"
          buttonsDisplay="block"
          values={value}
          onReset={() => onChange(false)}
          template={list}
          onFinish={async (formPanelObject: FormPanelObject) => {
            const vals = formPanelObject.getFieldsValue();
            const r = await StuNewStudentSrv.flowout(
              value.student_id,
              vals.departure_time.format('YYYY-MM-DD'),
              vals.departure_reason
            );
            if (r.success) {
              message.success('操作成功');
              onChange(false);
              formPanelObject?.resetFildes?.();
            } else {
              formPanelObject.reVaildation(r);
            }
          }}
        />
      </Modal>
    </>
  );
};

export default Create;
